<template>
  <div class="nav-menu">
    <div class="logo">
      <img class="img" src="@/assets/img/logo.svg" alt="logo" />
      <span class="title" v-show="!isFold">管理系统</span>
    </div>
    <el-menu 
     text-color="#b7bdc3" 
     active-text-color="#fff" 
     background-color="#001529" 
     :collapse-transition="false"
     :collapse="isFold">
      <el-sub-menu v-for="item in menus" :key="item.menuId" :index="String(item.menuId)">
        <template #title>
          <el-icon ><component :is="item.icon" /></el-icon>
          <span>{{ item.menuName }}</span>
        </template>
        <el-menu-item v-for="c in item.children" :key="c.menuId" :index="String(c.menuId)" @click="handleClickRoute(c)">
          <el-icon ><component :is="c.icon" /></el-icon>
          {{ c.menuName }}
        </el-menu-item>
      </el-sub-menu>
    </el-menu>
  </div>
</template>
<script setup lang="ts">

defineProps({
  isFold: {
    type: Boolean,
    default: false
  }
})

import useLoginStore from '@/store/login/login'
const loginStore = useLoginStore()
const menus = loginStore.userMenus


import router from '@/router'


function handleClickRoute(item:any){
  console.log({item:item.path});
  router.push(`/main/${item.path}`)
}

</script>

<style scoped lang="less">
.nav-menu {
  height: 100%;
  background-color: #001529;
  .el-menu{
    border-color:#0c2135;
  }
}

.logo {
  display: flex;
  height: 28px;
  padding: 12px 10px 8px 10px;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;

  .img {
    height: 100%;
    margin: 0 10px;
  }

  .title {
    font-size: 16px;
    font-weight: 700;
    color: white;
  }
}

.el-sub-menu {
  .el-menu-item {
    padding-left: 50px !important;
    background-color: #0c2135;
  }

  .el-menu-item:hover {
    color: #fff;
  }

  .el-menu-item.is-active {
    background-color: #0a60bd;
  }
}
</style>
